home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 4 / The Arsenal Files 4 (Arsenal Computer).ISO / ham / sattrk31.tgz / sattrack-3.1.tar / SatTrack / src / sattrack / satchar.c < prev    next >
C/C++ Source or Header  |  1995-03-16  |  13KB  |  385 lines

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /*  Title       : satchar.c                                                   */
  4. /*  Author      : Manfred Bester                                              */
  5. /*  Date        : 09Jul93                                                     */
  6. /*  Last change : 15Mar95                                                     */
  7. /*                                                                            */
  8. /*  Synopsis    : Routines for character string manipulation.                 */
  9. /*                                                                            */
  10. /*                                                                            */
  11. /*  SatTrack is Copyright (c) 1992, 1993, 1994, 1995 by Manfred Bester.       */
  12. /*  All Rights Reserved.                                                      */
  13. /*                                                                            */
  14. /*  Permission to use, copy, and distribute SatTrack and its documentation    */
  15. /*  in its entirety for educational, research and non-profit purposes,        */
  16. /*  without fee, and without a written agreement is hereby granted, provided  */
  17. /*  that the above copyright notice and the following three paragraphs appear */
  18. /*  in all copies. SatTrack may be modified for personal purposes, but        */
  19. /*  modified versions may NOT be distributed without prior consent of the     */
  20. /*  author.                                                                   */
  21. /*                                                                            */
  22. /*  Permission to incorporate this software into commercial products may be   */
  23. /*  obtained from the author, Dr. Manfred Bester, 1636 M. L. King Jr. Way,    */
  24. /*  Berkeley, CA 94709, USA. Note that distributing SatTrack 'bundled' in     */
  25. /*  with ANY product is considered to be a 'commercial purpose'.              */
  26. /*                                                                            */
  27. /*  IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, */
  28. /*  SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF   */
  29. /*  THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR HAS BEEN ADVISED  */
  30. /*  OF THE POSSIBILITY OF SUCH DAMAGE.                                        */
  31. /*                                                                            */
  32. /*  THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT      */
  33. /*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A   */
  34. /*  PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"      */
  35. /*  BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, */
  36. /*  UPDATES, ENHANCEMENTS, OR MODIFICATIONS.                                  */
  37. /*                                                                            */
  38. /******************************************************************************/
  39.  
  40. #include <stdio.h>
  41. #include <string.h>
  42.  
  43. #ifndef STDLIB
  44. #include <stdlib.h>
  45. #endif
  46.  
  47. #include "satglobalsx.h"
  48. #include "sattrack.h"
  49.  
  50. /******************************************************************************/
  51. /*                                                                            */
  52. /* mGets: Manfred's version of fgets (wipes out newline character at the end) */
  53. /*                                                                            */
  54. /*        if the graphics window is open this function also refreshes the     */
  55. /*        graphics if necessary                                               */
  56. /*                                                                            */
  57. /******************************************************************************/
  58.  
  59. void mGets(string)
  60.  
  61. char *string;
  62.  
  63. {
  64.     int  i, k;
  65.  
  66.     if (graphicsOpenFlag)
  67.     {
  68.         i = 0;
  69.  
  70.         do
  71.         {
  72.             k = checkKeyboard(TRUE);
  73.  
  74.             if (k > 0)
  75.             {
  76.                 if (k == 8)
  77.                 {
  78.                     if (i > 0)
  79.                     {
  80.                         printf("%c%c%c",(char) 8,(char) 8, (char) 8);
  81.                         printf("   ");
  82.                         printf("%c%c%c",(char) 8,(char) 8, (char) 8);
  83.                         fflush(stdout);
  84.                         i--;
  85.                     }
  86.  
  87.                     else
  88.                     {
  89.                         printf("%c%c",(char) 8,(char) 8);
  90.                         printf("  ");
  91.                         printf("%c%c",(char) 8,(char) 8);
  92.                         fflush(stdout);
  93.                     }
  94.                 }
  95.  
  96.                 else
  97.                 {
  98.                     string[i] = (char) k;
  99.                     i++;
  100.                 }
  101.             }
  102.  
  103.             if (graphicsOpenFlag)
  104.                 UpdateGraphics(FALSE);
  105.  
  106.             milliSleep(10);
  107.         }
  108.         while (k != 10 && k != 13);
  109.  
  110.         string[i] = '\0';
  111.     }
  112.  
  113.     else
  114.         fgets(string,80,stdin);
  115.  
  116.     i = (int) strlen(string);
  117.  
  118.     if (i > 0)
  119.         string[i-1] = '\0';
  120.     else
  121.         string[0]   = '\0';
  122.  
  123.     return;
  124. }
  125.  
  126. /******************************************************************************/
  127. /*                                                                            */
  128. /* upperCase: changes lower to upper case letters                             */
  129. /*                                                                            */
  130. /******************************************************************************/
  131.  
  132. void upperCase(string)
  133.  
  134. char *string;
  135.  
  136. {
  137.     int i;
  138.  
  139.     for (i = 0; i < (int) strlen(string); i++)
  140.     {
  141.         if (string[i] >= 'a' && string[i] <= 'z')
  142.             string[i] -= 'a' - 'A';
  143.     }
  144.  
  145.     return;
  146. }
  147.  
  148. /******************************************************************************/
  149. /*                                                                            */
  150. /* lowerCase: changes upper to lower case letters                             */
  151. /*                                                                            */
  152. /******************************************************************************/
  153.  
  154. void lowerCase(string)
  155.  
  156. char *string;
  157.  
  158. {
  159.     int i;
  160.  
  161.     for (i = 0; i < (int) strlen(string); i++)
  162.     {
  163.         if (string[i] >= 'A' && string[i] <= 'Z')
  164.             string[i] -= 'A' - 'a';
  165.     }
  166.  
  167.     return;
  168. }
  169.  
  170. /******************************************************************************/
  171. /*                                                                            */
  172. /* truncBlanks: truncates trailing blanks from character string               */
  173. /*                                                                            */
  174. /******************************************************************************/
  175.  
  176. void truncBlanks(string)
  177.  
  178. char *string;
  179.  
  180. {
  181.     int i;
  182.  
  183.     i = (int) strlen(string) - 1;
  184.  
  185.     while (string[i] == ' ')
  186.     {
  187.         i--;
  188.     }
  189.  
  190.     string[i+1] = '\0';                          /* add termination character */
  191.     return;
  192. }
  193.  
  194. /******************************************************************************/
  195. /*                                                                            */
  196. /* shortString: shortens character string up to next blank from the end       */
  197. /*                                                                            */
  198. /******************************************************************************/
  199.  
  200. void shortString(strng,fullStrng,maxLen)
  201.  
  202. int  maxLen;
  203. char *strng, *fullStrng;
  204.  
  205. {
  206.     int i;
  207.  
  208.     strncpy(strng,fullStrng,maxLen);
  209.  
  210.     if ((int) strlen(strng) == maxLen)
  211.     {
  212.         if (fullStrng[maxLen-1] == ' ')
  213.             strng[maxLen-1] = '\0';
  214.  
  215.         else
  216.         {
  217.             if (fullStrng[maxLen] != ',' && fullStrng[maxLen] != ' ')
  218.             {
  219.                 i = (int) strlen(strng) - 1;
  220.  
  221.                 do
  222.                 {
  223.                     i--;
  224.                 }
  225.                 while (strng[i] != ' ');
  226.  
  227.                 strng[i] = '\0';
  228.             }
  229.         }
  230.  
  231.         for (i = 0; i < maxLen; i++)
  232.         {
  233.             if (strng[i] == ',')
  234.                 strng[i] = '\0';
  235.         }
  236.     }
  237.  
  238.     return;
  239. }
  240.  
  241. /******************************************************************************/
  242. /*                                                                            */
  243. /* clipString: clips N characters plus leading blanks off the beginning of a  */
  244. /*             character string                                               */
  245. /*                                                                            */
  246. /******************************************************************************/
  247.  
  248. void clipString(charStr,N)
  249.  
  250. int  N;
  251. char *charStr;
  252.  
  253. {
  254.     int  i, j, firstChar;
  255.     char tmpStr[100];
  256.  
  257.     firstChar = FALSE;
  258.     j = 0;
  259.  
  260.     for (i = 0; i < (int) strlen(charStr) - N; i++) 
  261.     {
  262.  
  263.         if (charStr[i+N] != ' ' || (charStr[i+N] == ' ' && firstChar))
  264.         {
  265.             tmpStr[j] = charStr[i+N];
  266.             j++;
  267.             firstChar = TRUE;
  268.         }
  269.     }
  270.  
  271.     tmpStr[j] = '\0';                            /* add termination character */
  272.     sprintf(charStr,"%s",tmpStr);
  273.     return;
  274. }
  275.  
  276. /******************************************************************************/
  277. /*                                                                            */
  278. /* cleanSatName: cleans up satellite name                                     */
  279. /*                                                                            */
  280. /******************************************************************************/
  281.  
  282. void cleanSatName(charStr)
  283.  
  284. char *charStr;
  285.  
  286. {
  287.     int  i;
  288.  
  289.     if ((int) strlen(charStr) > MAXSATNAMELEN)
  290.         charStr[MAXSATNAMELEN] = '\0';
  291.  
  292.     if (charStr[MAXSATNAMELEN-1] == '/' ||
  293.         charStr[MAXSATNAMELEN-1] == ' ')
  294.         charStr[MAXSATNAMELEN-1] = '\0';
  295.  
  296.     for (i = 0; i < (int) strlen(charStr); i++)
  297.     {
  298.         if (charStr[i] == '(')
  299.             charStr[i] = '\0';
  300.     }
  301.  
  302.     return;
  303. }
  304.  
  305. /******************************************************************************/
  306. /*                                                                            */
  307. /* replaceBlanks: replaces underscore characters by a blank character         */
  308. /*                                                                            */
  309. /******************************************************************************/
  310.  
  311. void replaceBlanks(charStr)
  312.  
  313. char *charStr;
  314.  
  315. {
  316.     int  i;
  317.  
  318.     for (i = 0; i < (int) strlen(charStr); i++)
  319.     {
  320.         if (charStr[i] == '_')
  321.             charStr[i] = ' ';
  322.     }
  323.  
  324.     return;
  325. }
  326.  
  327. /******************************************************************************/
  328. /*                                                                            */
  329. /* getSiteNameID: retrieves site ID from site name string                     */
  330. /*                                                                            */
  331. /*                the site ID has to be in '()' and cannot be the last part   */
  332. /*                of the site name; in other words there has to be a comma or */
  333. /*                a blank behind the closing bracket of the site ID           */
  334. /*                                                                            */
  335. /*                allowed examples:                                           */
  336. /*                                                                            */
  337. /*                Diego Garcia (DGS) (UK)                --> DGS              */
  338. /*                Kennedy Space Center (KSC), FL, USA    --> KSC              */
  339. /*                                                                            */
  340. /******************************************************************************/
  341.  
  342. void getSiteNameID(string)
  343.  
  344. char *string;
  345.  
  346. {
  347.     int i, j, k;
  348.     char str[80];
  349.  
  350.     i = 0;
  351.     j = 0;
  352.     k = (int) strlen(string);
  353.  
  354.     do
  355.     {
  356.        i++;
  357.     }
  358.     while (string[i] != '(' && i < k);
  359.  
  360.     i++;
  361.  
  362.     do
  363.     {
  364.         str[j] = string[i];
  365.         i++;
  366.         j++;
  367.     }
  368.     while (string[i] != ')' && i < k);
  369.  
  370.     str[j] = '\0';
  371.  
  372.     if (string[i] != ',' && string[i] != ' ' && i < k-1)
  373.         sprintf(string,"%s",str);
  374.     else
  375.         *string = '\0';
  376.  
  377.     return;
  378. }
  379.  
  380. /******************************************************************************/
  381. /*                                                                            */
  382. /* End of function block satchar.c                                            */
  383. /*                                                                            */
  384. /******************************************************************************/
  385.